﻿using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.ViewModel;
using System.Diagnostics.Contracts;
using System.Windows;
using System.Windows.Threading;

namespace Neudesic.Pulse.ViewModels
{
    /// <summary>
    /// Base viewmodel object
    /// </summary>
    public class ViewModel : NotificationObject
    {

        /// <summary>
        /// Gets or sets the event aggregator.
        /// </summary>
        /// <value>The event aggregator.</value>
        protected IEventAggregator EventAggregator { get; set; }

        protected Dispatcher Dispatcher { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="ViewModel" /> class.
        /// </summary>
        /// <param name="eventAggregator">The event aggregator.</param>
        public ViewModel(IEventAggregator eventAggregator)
        {

            this.EventAggregator = eventAggregator;

            // Grab the dispatcher for this viewmodel
            if (Application.Current != null)
            {
                this.Dispatcher = Application.Current.Dispatcher;
            }
            else
            {
                // Only used for unit tests where no application is running.
                Dispatcher = Dispatcher.CurrentDispatcher;
            }

        }

    }
}
